﻿using CommonDevelop;
using CommonEngine;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using WebWap.Models;

namespace WebWap.Controllers
{
    /// <summary>
    /// 工作环境
    /// </summary>
    public class WorkDoneController : Controller
    {
        private readonly IPathProvider pathProvider;
        /// <summary>
        /// 构造
        /// </summary>
        public WorkDoneController(IPathProvider pathProvider)
        {
            this.pathProvider = pathProvider;
        }

        /// <summary>
        /// 404
        /// </summary>
        public IActionResult Error404()
        {
            ViewBag.Title = "404";
            return View();
        }

        /// <summary>
        /// 测试error
        /// </summary>
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error(int id)
        {
            int code = id;
            ViewBag.Title = "Error";
            if (code == 401)
                return RedirectToAction("Login", "Login");  //验证失败
            else if (code == 403)   //API环境中重新配置
                return Json(new ResponseParameter { code = ResponseCode.fail, info = "未授权" });
            else if (code == 404)   //API环境中重新配置
                return RedirectToAction("Error404", "WorkDone");
            else
                return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier, code = code });
        }
    }
}